import 'package:flutter/material.dart';

import '../utils/message.dart';

class ExitPopScope extends StatelessWidget {
  final Widget child;

  ExitPopScope({this.child});

  Future<bool> _onWillPop(BuildContext context) async {
    var result = await MessageUtil.confirm(
      context,
      '是否退出？',
      buttons: AlertActionButton.yesNo,
    );
    return result == AlertActionResult.yes ? true : false;
  }

  @override
  Widget build(BuildContext context) {
    return new WillPopScope(
      onWillPop: () {
        return _onWillPop(context);
      },
      child: child,
    );
  }
}
